import sys, os
import importlib
import pythoncom
import win32com.client
import win32com.server.util



class Utilities:
    def __init__(self): 
        self.constants = pythoncom #调取COM常量设定

    def VARIANT(self, vt, value): #转换变量为COM类型
        return win32com.client.VARIANT(vt, value)

    def wrap(self, ob): #包装对象供COM使用
        return win32com.server.util.wrap(ob)

    def unwrap(self, ob): #解包被wrap的对象
        return win32com.server.util.unwrap(ob)

    def CreateObject(self, name):
        return win32com.client.Dispatch(name)

def __factory(name): #加载并加工模块
    constructor = importlib.import_module('modules.%s' % (name)).Handler
    constructor.compilation = Utilities()
    return constructor


instance = __factory("excel")()
print(instance.open("D:\development\Project\PythonActiveX\sample.xls"))

sheet = instance.sheet("标准格式")

sheet2 = instance.compilation.unwrap(sheet)
# instance.compilation.unwrap(sheet2.dataTranslation()).loadPreset()
sheet2.setHDR(False)

dom = sheet2.toXML()

print(dom.xml)


# print(sheet2.getHeader())


# instance = __factory("zip")()
# print(instance.load("D:\development\Project\PythonActiveX\mformats.zip"))

# instance.write("copy", 'msxml6.txt', 'D:\development\Project\PythonActiveX\msxml6.txt')
# instance.write("copy", 'IPippo.txt', 'D:\development\Project\PythonActiveX\IPippo.txt')
# instance.write("copy", 'cs\IPippo.txt', 'D:\development\Project\PythonActiveX\IPippo.txt')

# instance.write("create", 'cs.txt', '在 3.8 版更改: exists()、lexists()、isdir()、isfile()、islink() 和 ismount() 现在遇到系统层面上不可表示的字符或字节的路径时，会返回 False，而不是抛出异常。')


